package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.UnBindMailBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.UnBindMailCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*绑定邮箱Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UnBindEmail{
	private static UnBindMailBean UnBindMailBean;
	private static UnBindMailCall UnBindMailCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("绑定邮箱");
	}

	@Before
	public void caseUp() {
		UnBindMailBean=new UnBindMailBean();
		UnBindMailCall=new UnBindMailCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(UnBindMailCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UnBindEmail_001() {
		Logger.start(true,"解除绑定邮箱,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			JUserCallService.BindEmail(uid, TestDataManager.getEmail());
			UnBindMailBean.setUserId(uid);
			UnBindMailCall.setData(UnBindMailBean);
			UnBindMailCall.callService();			
			Logger.verifyEquals("true", UnBindMailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", UnBindMailCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(null, ui.getLoginMail(), "验证mail");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UnBindEmail_002() {
		Logger.start(false,"重复解除绑定邮箱,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			JUserCallService.BindEmail(uid, TestDataManager.getEmail());
			UnBindMailBean.setUserId(uid);
			UnBindMailCall.setData(UnBindMailBean);
			UnBindMailCall.callService();	
			UnBindMailCall.callService();	
			Logger.verifyEquals("true", UnBindMailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", UnBindMailCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(null, ui.getLoginMail(), "验证mail");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UnBindEmail_003() {
		Logger.start(false,"邮箱未绑定,判断为成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			UnBindMailBean.setUserId(uid);
			UnBindMailCall.setData(UnBindMailBean);
			UnBindMailCall.callService();	
			Logger.verifyEquals("true", UnBindMailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", UnBindMailCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(null, ui.getLoginMail(), "验证mail");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UnBindEmail_004() {
		Logger.start(false,"不输入userid,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
//			UnBindMailBean.setUserId(uid);
			UnBindMailCall.setData(UnBindMailBean);
			UnBindMailCall.callService();
			Logger.verifyEquals("false", UnBindMailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", UnBindMailCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("无效的用户Id", UnBindMailCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UnBindEmail_005() {
		Logger.start(false,"输入不存在userid,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			UnBindMailBean.setUserId(-999);
			UnBindMailCall.setData(UnBindMailBean);
			UnBindMailCall.callService();
			Logger.verifyEquals("false", UnBindMailCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", UnBindMailCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("无效的用户Id", UnBindMailCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}